package com.atguigu

import org.apache.spark.{SparkConf, SparkContext}

object WordCount {

  def main(args: Array[String]): Unit = {

    //1.创建SparkConf并设置App名称
    val conf: SparkConf = new SparkConf().setAppName("WC").setMaster("local[*]")

    //2.创建SparkContext，该对象是提交Spark App的入口
    val sc: SparkContext = new SparkContext(conf)

    //3.使用sc创建RDD并执行相应的transformation和action
    val unit: Unit = sc.textFile(args(0)).flatMap(_.split(" ")).map((_, 1))
      .reduceByKey(_ + _, 1).sortBy(_._2, false)
      .saveAsTextFile(args(1))

    //4.关闭连接
    sc.stop()

  }
}
